% ************************************************************************ 
%     Module name   : Lynx Simulation - Radar Run                                                     
%                                                                          
%     Description   : This will run the Track mode on a specific target.                                                    
%                                                                          
%     $Header: /Lynx/SimulationFramework/RSP/IFS/IFSRun.m 2     15/10/08 16:08 Lwabeke $ 
%                                                                          
%    $Author: Lwabeke $	            
%                                                                         
%    $Revision: 2 $                
%                                                                         
% ************************************************************************
%     $History: IFSRun.m $ 
% 
%
% ************************************************************************
function [new_radarState, new_time, changedInfo] = Radar_Run(time, radarState, tgtCntr, radarSetup, param)
global worldState;

radarSetup.usedTime = radarSetup.deltaTime(tgtCntr);
new_time = time + radarSetup.usedTime;
if (tgtCntr == 1)
    radarState.targetVisit = 1;
else
    radarState.targetVisit = radarState.targetVisit + 1;
end

if (param.display.perTarget)
    figure(3)
    hold off;
    for cntr = 1:worldState.activeTargets  %radarState.TargetList.numTargets
        %         plot(worldState.Target(radarState.TargetList.Targets(cntr).id).currentPos(1), worldState.Target(radarState.TargetList.Targets(cntr).id).currentPos(2), 'g.')
        plot(worldState.Target(cntr).currentPos(1), worldState.Target(cntr).currentPos(2), 'g.')
        hold on;
    end
end

for radarCnt = 1:param.num_radars
    radarState.radar(radarCnt).posAngle = radarState.radar(radarCnt).posAngle + radarSetup.angleRates(tgtCntr, radarCnt) * radarSetup.usedTime;
    
    if (param.display.perTarget)
        radarLOS = radarState.radar(radarCnt).radarLocation;
        radarLOS(2,:) = radarState.radar(radarCnt).radarLocation + [cos(radarState.radar(radarCnt).posAngle) sin(radarState.radar(radarCnt).posAngle)] * 60000;
        
        plot(radarLOS(:,1), radarLOS(:,2));
    end
end

if (param.display.perTarget)
    
    title('View at double tracking target')
    axis(param.world.area)
    drawnow;
    if (param.display.perTarget > 1)
        pause(0.3)
    end
end

% radarState.radarSetup = radarSetup;
% 
% changedInfo.radarSetup = radarSetup;
% changedInfo.usedTime = radarSetup.usedTime;
% 
%  switch radarSetup.mode
%             case {'Search'}
%                             [newTargets] = SearchMode_Run(time, param, radarSetup, radarState.TargetList);
%                             
%                             if (size(newTargets) > 0)
%                                 if (radarState.TargetList.numTargets == 0)||(~isstruct(radarState.TargetList.Targets(1)))
%                                     radarState.TargetList.Targets = newTargets;
%                                 else
%                                     radarState.TargetList.Targets(radarState.TargetList.numTargets+1:radarState.TargetList.numTargets+size(newTargets,2)) = newTargets;
%                                 end
%                                 radarState.TargetList.numTargets = size(radarState.TargetList.Targets,2);
%                             end
%                             
%                             changedInfo.newTargets = newTargets; 
%                             
%                             sector = radarSetup.sector;
%                             
%                             switch (radarSetup.subMode)
%                                 case 'NCI'
%                                     radarState.search.time_NCI(sector) = new_time;
%                                 case 'MTI'
%                                     radarState.search.time_MTI(sector) = new_time;
%                                 case 'Stationary';
%                                     radarState.search.time_Stationary(sector) = new_time;
%                             end
% 
%                             new_state_estimate = state_estimate_search(new_time, radarState);
%                             changedInfo.radarSetup.new_state_estimate = new_state_estimate;
% 
%                             
% 
%             case {'Acq'}
%                             [newTargetEst] = AcquisitionMode_Run(time, param, radarSetup, radarState.TargetList.Targets(tgtCntr), worldState);
%                             
%                             radarState.TargetList.Targets(tgtCntr) = newTargetEst;
%                             
%                             changedInfo.updatedTargets = newTargetEst;
%                             changedInfo.oldTargets = newTargetEst;
%                             
%                             
%             case {'Track'}
%                             [newTargetEst] = TrackMode_Run(time, param, radarSetup, radarState.TargetList.Targets(tgtCntr), worldState);
%                             
%                             radarState.TargetList.Targets(tgtCntr) = newTargetEst;
% 
%                             changedInfo.updatedTargets = newTargetEst;
%                             changedInfo.oldTargets = newTargetEst;
%                             
%                             
%             case {'Classify'}
%                             [newTargetEst] = ClassifyMode_Run(time, param, radarSetup, radarState.TargetList.Targets(tgtCntr), worldState);
%                             
%                             radarState.TargetList.Targets(tgtCntr) = newTargetEst;
%                             
%                             changedInfo.updatedTargets = newTargetEst;
%                             changedInfo.oldTargets = newTargetEst;
%                             
%  end
%                             
% 
% 
new_radarState = radarState;

changedInfo = [];